const moment = require('./moment.js');
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

// 设置时区为UTC，以确保Moment.js和Moment4CJ使用相同的时间环境
process.env.TZ = 'UTC';

// 验证报告
let validationReport = {
    summary: {
        totalTests: 0,
        passedTests: 0,
        failedTests: 0
    },
    testCases: []
};

// 添加测试结果到报告
function addTestResult(name, passed, momentResult, moment4cjResult, details = '') {
    validationReport.summary.totalTests++;
    if (passed) {
        validationReport.summary.passedTests++;
    } else {
        validationReport.summary.failedTests++;
    }
    
    validationReport.testCases.push({
        name: name,
        passed: passed,
        momentResult: momentResult,
        moment4cjResult: moment4cjResult,
        details: details
    });
}

// 运行Moment4CJ测试并获取结果
function runMoment4CJTests() {
    try {
        // 使用cjpm test命令运行测试，并使用过滤器只运行交叉验证测试
        const env = Object.assign({}, process.env);
        
        // 获取项目根目录路径
        const projectRoot = path.resolve(__dirname, '..');
        
        // 运行测试并捕获输出
        const output = execSync('cjpm test --filter="*CrossValidation*" --show-all-output', { 
            encoding: 'utf-8',
            stdio: ['pipe', 'pipe', 'pipe'],
            shell: '/bin/zsh',
            cwd: projectRoot,
            env: env
        });
        return output;
    } catch (error) {
        console.error('运行Moment4CJ测试时出错:', error.message);
        // 即使出错也返回输出（如果有的话）
        if (error.stdout) {
            return error.stdout;
        }
        return '';
    }
}

// 解析Moment4CJ测试结果
function parseMoment4CJResults(output) {
    const results = {};
    
    // 解析时间加法结果
    const addMatch = output.match(/CROSS_VALIDATION_TIME_ADDITION_RESULT: (\d+)/);
    if (addMatch) {
        results.timeAddition = parseInt(addMatch[1]);
    }
    
    // 解析时间减法结果
    const subtractMatch = output.match(/CROSS_VALIDATION_TIME_SUBTRACTION_RESULT: (\d+)/);
    if (subtractMatch) {
        results.timeSubtraction = parseInt(subtractMatch[1]);
    }
    
    // 解析时间差结果
    const diffMatch = output.match(/CROSS_VALIDATION_TIME_DIFF_RESULT: (\d+)/);
    if (diffMatch) {
        results.timeDiff = parseInt(diffMatch[1]);
    }
    
    // 解析单位别名结果
    const aliasMatch = output.match(/CROSS_VALIDATION_UNIT_ALIASES_RESULT: (true|false)/);
    if (aliasMatch) {
        results.unitAliases = aliasMatch[1] === 'true';
    }
    
    // 解析月末日期处理结果
    const endOfMonthMatch = output.match(/CROSS_VALIDATION_END_OF_MONTH_RESULT: ([\d-]+)/);
    if (endOfMonthMatch) {
        results.endOfMonth = endOfMonthMatch[1];
    }
    
    // 解析格式化结果
    const formatMatch = output.match(/CROSS_VALIDATION_FORMAT_RESULT: ([\d:-]+ [\d:]+)/);
    if (formatMatch) {
        results.format = formatMatch[1];
    }
    
    // 解析时间比较结果
    const isSameMatch = output.match(/CROSS_VALIDATION_IS_SAME_RESULT: (true|false)/);
    if (isSameMatch) {
        results.isSame = isSameMatch[1] === 'true';
    }
    
    // 解析闰年处理结果
    const leapYearMatch = output.match(/CROSS_VALIDATION_LEAP_YEAR_RESULT: ([\d-]+)/);
    if (leapYearMatch) {
        results.leapYear = leapYearMatch[1];
    }
    
    // 解析多单位操作结果
    const multipleUnitsMatch = output.match(/CROSS_VALIDATION_MULTIPLE_UNITS_RESULT: ([\d-]+)/);
    if (multipleUnitsMatch) {
        results.multipleUnits = multipleUnitsMatch[1];
    }
    
    // 解析startOf结果
    const startOfMatch = output.match(/CROSS_VALIDATION_START_OF_RESULT: ([\d:-]+ [\d:]+)/);
    if (startOfMatch) {
        results.startOf = startOfMatch[1];
    }
    
    // 解析endOf结果
    const endOfMatch = output.match(/CROSS_VALIDATION_END_OF_RESULT: ([\d:-]+ [\d:]+)/);
    if (endOfMatch) {
        results.endOf = endOfMatch[1];
    }
    
    // 解析星期几结果
    const dayOfWeekMatch = output.match(/CROSS_VALIDATION_DAY_OF_WEEK_RESULT: (\d+)/);
    if (dayOfWeekMatch) {
        results.dayOfWeek = parseInt(dayOfWeekMatch[1]);
    }
    
    // 解析一年中的第几天结果
    const dayOfYearMatch = output.match(/CROSS_VALIDATION_DAY_OF_YEAR_RESULT: (\d+)/);
    if (dayOfYearMatch) {
        results.dayOfYear = parseInt(dayOfYearMatch[1]);
    }
    
    // 解析一年中的第几周结果
    const weekOfYearMatch = output.match(/CROSS_VALIDATION_WEEK_OF_YEAR_RESULT: (\d+)/);
    if (weekOfYearMatch) {
        results.weekOfYear = parseInt(weekOfYearMatch[1]);
    }
    
    // 解析week结果
    const weekMatch = output.match(/CROSS_VALIDATION_WEEK_RESULT: (\d+)/);
    if (weekMatch) {
        results.week = parseInt(weekMatch[1]);
    }
    
    // 解析isoWeek结果
    const isoWeekMatch = output.match(/CROSS_VALIDATION_ISO_WEEK_RESULT: (\d+)/);
    if (isoWeekMatch) {
        results.isoWeek = parseInt(isoWeekMatch[1]);
    }
    
    // 解析weeks结果
    const weeksMatch = output.match(/CROSS_VALIDATION_WEEKS_RESULT: (\d+)/);
    if (weeksMatch) {
        results.weeks = parseInt(weeksMatch[1]);
    }
    
    // 解析年末week结果
    const endOfYearWeekMatch = output.match(/CROSS_VALIDATION_END_OF_YEAR_WEEK_RESULT: (\d+)/);
    if (endOfYearWeekMatch) {
        results.endOfYearWeek = parseInt(endOfYearWeekMatch[1]);
    }
    
    // 解析年末weeks结果
    const endOfYearWeeksMatch = output.match(/CROSS_VALIDATION_END_OF_YEAR_WEEKS_RESULT: (\d+)/);
    if (endOfYearWeeksMatch) {
        results.endOfYearWeeks = parseInt(endOfYearWeeksMatch[1]);
    }
    
    // 解析isoWeeks结果
    const isoWeeksMatch = output.match(/CROSS_VALIDATION_ISO_WEEKS_RESULT: (\d+)/);
    if (isoWeeksMatch) {
        results.isoWeeks = parseInt(isoWeeksMatch[1]);
    }
    
    // 解析季度结果
    const quarterMatch = output.match(/CROSS_VALIDATION_QUARTER_RESULT: (\d+)/);
    if (quarterMatch) {
        results.quarter = parseInt(quarterMatch[1]);
    }
    
    // 解析get结果
    const getMatch = output.match(/CROSS_VALIDATION_GET_RESULT: ([\d,]+)/);
    if (getMatch) {
        const parts = getMatch[1].split(',');
        results.get = {
            year: parseInt(parts[0]),
            month: parseInt(parts[1]),
            date: parseInt(parts[2])
        };
    }
    
    // 解析set结果
    const setMatch = output.match(/CROSS_VALIDATION_SET_RESULT: ([\d-]+)/);
    if (setMatch) {
        results.set = setMatch[1];
    }
    
    // 解析Unix时间戳结果
    const unixTimestampMatch = output.match(/CROSS_VALIDATION_UNIX_TIMESTAMP_RESULT: (\d+)/);
    if (unixTimestampMatch) {
        results.unixTimestamp = parseInt(unixTimestampMatch[1]);
    }
    
    // 解析月份天数结果
    const daysInMonthMatch = output.match(/CROSS_VALIDATION_DAYS_IN_MONTH_RESULT: (\d+)/);
    if (daysInMonthMatch) {
        results.daysInMonth = parseInt(daysInMonthMatch[1]);
    }
    
    // 解析calendar结果
    const calendarMatch = output.match(/CROSS_VALIDATION_CALENDAR_RESULT: (.+)/);
    if (calendarMatch) {
        results.calendar = calendarMatch[1];
    }
    
    // 解析calendar same day结果
    const calendarSameDayMatch = output.match(/CROSS_VALIDATION_CALENDAR_SAME_DAY_RESULT: (.+)/);
    if (calendarSameDayMatch) {
        results.calendarSameDay = calendarSameDayMatch[1];
    }
    
    // 解析calendar next day结果
    const calendarNextDayMatch = output.match(/CROSS_VALIDATION_CALENDAR_NEXT_DAY_RESULT: (.+)/);
    if (calendarNextDayMatch) {
        results.calendarNextDay = calendarNextDayMatch[1];
    }
    
    // 解析calendar last week结果
    const calendarLastWeekMatch = output.match(/CROSS_VALIDATION_CALENDAR_LAST_WEEK_RESULT: (.+)/);
    if (calendarLastWeekMatch) {
        results.calendarLastWeek = calendarLastWeekMatch[1];
    }
    
    // 解析calendar next week结果
    const calendarNextWeekMatch = output.match(/CROSS_VALIDATION_CALENDAR_NEXT_WEEK_RESULT: (.+)/);
    if (calendarNextWeekMatch) {
        results.calendarNextWeek = calendarNextWeekMatch[1];
    }
    
    // 解析calendar same else结果
    const calendarSameElseMatch = output.match(/CROSS_VALIDATION_CALENDAR_SAME_ELSE_RESULT: (.+)/);
    if (calendarSameElseMatch) {
        results.calendarSameElse = calendarSameElseMatch[1];
    }
    
    return results;
}

// 执行交叉验证测试
function performCrossValidation() {
    console.log('开始执行交叉验证测试...');
    
    // 运行Moment4CJ测试
    console.log('运行Moment4CJ交叉验证测试...');
    const moment4cjOutput = runMoment4CJTests();
    const moment4cjResults = parseMoment4CJResults(moment4cjOutput);
    
    // 执行Moment.js测试并比较结果
    console.log('执行Moment.js测试并比较结果...');
    
    // 测试时间加法
    // 输入: moment('2021-01-01T00:00:00Z'), add(1, "day")
    const baseTime = moment('2021-01-01T00:00:00Z');
    const momentJsAddResult = baseTime.clone().add(1, "day").unix();
    const moment4cjAddResult = moment4cjResults.timeAddition;
    const addPassed = momentJsAddResult === moment4cjAddResult;
    
    addTestResult(
        '时间加法测试',
        addPassed,
        momentJsAddResult.toString(),
        moment4cjAddResult ? moment4cjAddResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), add(1, "day")'
    );
    
    // 测试时间减法
    // 输入: moment('2021-01-01T00:00:00Z'), subtract(1, "day")
    const momentJsSubtractResult = baseTime.clone().subtract(1, "day").unix();
    const moment4cjSubtractResult = moment4cjResults.timeSubtraction;
    const subtractPassed = momentJsSubtractResult === moment4cjSubtractResult;
    
    addTestResult(
        '时间减法测试',
        subtractPassed,
        momentJsSubtractResult.toString(),
        moment4cjSubtractResult ? moment4cjSubtractResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), subtract(1, "day")'
    );
    
    // 测试时间差计算
    // 输入: moment1 = moment('2021-01-01T00:00:00Z'),
    //       moment2 = moment1.clone().add(3600, 'seconds'),
    //       diff(moment2, moment1, 'seconds')
    const moment1 = moment('2021-01-01T00:00:00Z');
    const moment2 = moment1.clone().add(3600, 'seconds'); // 加1小时
    const momentJsDiffResult = moment2.diff(moment1, 'seconds');
    const moment4cjDiffResult = moment4cjResults.timeDiff;
    const diffPassed = momentJsDiffResult === moment4cjDiffResult;
    
    addTestResult(
        '时间差计算(秒)',
        diffPassed,
        momentJsDiffResult.toString(),
        moment4cjDiffResult ? moment4cjDiffResult.toString() : 'N/A',
        '输入: moment1 = moment(\'2021-01-01T00:00:00Z\'), moment2 = moment1.clone().add(3600, \'seconds\'), diff(moment2, moment1, \'seconds\')'
    );
    
    // 测试单位别名一致性
    // 输入: moment('2021-01-01T00:00:00Z'),
    //       add(30, 'seconds'), add(30, 'second'), add(30, 's')
    const secondsResult1 = baseTime.clone().add(30, 'seconds');
    const secondsResult2 = baseTime.clone().add(30, 'second');
    const secondsResult3 = baseTime.clone().add(30, 's');
    const momentJsAliasResult = secondsResult1.isSame(secondsResult2) && secondsResult2.isSame(secondsResult3);
    const moment4cjAliasResult = moment4cjResults.unitAliases;
    const aliasPassed = momentJsAliasResult === moment4cjAliasResult;
    
    addTestResult(
        '单位别名一致性测试',
        aliasPassed,
        momentJsAliasResult.toString(),
        moment4cjAliasResult !== undefined ? moment4cjAliasResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), add(30, \'seconds\'), add(30, \'second\'), add(30, \'s\')'
    );
    
    // 测试月末日期处理
    // 输入: moment('2021-01-01T00:00:00Z').add(30, 'days') 得到 2021-01-31T00:00:00Z,
    //       再 add(1, 'month')
    // 使用与Moment4CJ中完全相同的日期：2021-01-31T00:00:00Z
    const jan31 = moment('2021-01-01T00:00:00Z').add(30, 'days'); // 2021-01-31T00:00:00Z
    const momentJsEndOfMonthResult = jan31.clone().add(1, 'month').format('YYYY-MM-DD');
    const moment4cjEndOfMonthResult = moment4cjResults.endOfMonth;
    const endOfMonthPassed = momentJsEndOfMonthResult === moment4cjEndOfMonthResult;
    
    addTestResult(
        '月末日期处理测试',
        endOfMonthPassed,
        momentJsEndOfMonthResult,
        moment4cjEndOfMonthResult || 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\').add(30, \'days\') 得到 2021-01-31T00:00:00Z, 再 add(1, \'month\')'
    );
    
    // 测试时间格式化
    // 输入: moment('2021-01-01T00:00:00Z'), format('YYYY-MM-DD HH:mm:ss')
    const momentJsFormatResult = baseTime.utc().format('YYYY-MM-DD HH:mm:ss');
    const moment4cjFormatResult = moment4cjResults.format;
    const formatPassed = momentJsFormatResult === moment4cjFormatResult;
    
    addTestResult(
        '时间格式化测试',
        formatPassed,
        momentJsFormatResult,
        moment4cjFormatResult || 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), format(\'YYYY-MM-DD HH:mm:ss\')'
    );
    
    // 测试时间比较
    // 输入: moment('2021-01-01T00:00:00Z'), isSame(moment('2021-01-01T00:00:00Z'))
    const momentJsIsSameResult = moment('2021-01-01T00:00:00Z').isSame(moment('2021-01-01T00:00:00Z'));
    const moment4cjIsSameResult = moment4cjResults.isSame;
    const isSamePassed = momentJsIsSameResult === moment4cjIsSameResult;
    
    addTestResult(
        '时间比较测试',
        isSamePassed,
        momentJsIsSameResult.toString(),
        moment4cjIsSameResult !== undefined ? moment4cjIsSameResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), isSame(moment(\'2021-01-01T00:00:00Z\'))'
    );
    
    // 测试闰年处理
    // 输入: moment('2020-02-29T00:00:00Z'), add(1, 'year')
    const feb29_2020 = moment('2020-02-29T00:00:00Z');
    const momentJsLeapYearResult = feb29_2020.clone().add(1, 'year').format('YYYY-MM-DD');
    const moment4cjLeapYearResult = moment4cjResults.leapYear;
    const leapYearPassed = momentJsLeapYearResult === moment4cjLeapYearResult;
    
    addTestResult(
        '闰年处理测试',
        leapYearPassed,
        momentJsLeapYearResult,
        moment4cjLeapYearResult || 'N/A',
        '输入: moment(\'2020-02-29T00:00:00Z\'), add(1, \'year\')'
    );
    
    // 测试多单位操作
    // 输入: moment('2021-01-01T00:00:00Z'),
    //       add(1, 'year').add(1, 'month').add(1, 'day')
    const momentJsMultipleUnitsResult = baseTime.clone().add(1, 'year').add(1, 'month').add(1, 'day').format('YYYY-MM-DD');
    const moment4cjMultipleUnitsResult = moment4cjResults.multipleUnits;
    const multipleUnitsPassed = momentJsMultipleUnitsResult === moment4cjMultipleUnitsResult;
    
    addTestResult(
        '多单位操作测试',
        multipleUnitsPassed,
        momentJsMultipleUnitsResult,
        moment4cjMultipleUnitsResult || 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), add(1, \'year\').add(1, \'month\').add(1, \'day\')'
    );
    
    // 测试startOf功能
    // 输入: moment('2021-01-02T00:00:00Z'), startOf('day')
    const specificTime = moment('2021-01-02T00:00:00Z');
    const momentJsStartOfResult = specificTime.clone().startOf('day').format('YYYY-MM-DD HH:mm:ss');
    const moment4cjStartOfResult = moment4cjResults.startOf;
    const startOfPassed = momentJsStartOfResult === moment4cjStartOfResult;
    
    addTestResult(
        'StartOf功能测试',
        startOfPassed,
        momentJsStartOfResult,
        moment4cjStartOfResult || 'N/A',
        '输入: moment(\'2021-01-02T00:00:00Z\'), startOf(\'day\')'
    );
    
    // 测试endOf功能
    // 输入: moment('2021-01-02T00:00:00Z'), endOf('day')
    const momentJsEndOfResult = specificTime.clone().endOf('day').format('YYYY-MM-DD HH:mm:ss');
    const moment4cjEndOfResult = moment4cjResults.endOf;
    const endOfPassed = momentJsEndOfResult === moment4cjEndOfResult;
    
    addTestResult(
        'EndOf功能测试',
        endOfPassed,
        momentJsEndOfResult,
        moment4cjEndOfResult || 'N/A',
        '输入: moment(\'2021-01-02T00:00:00Z\'), endOf(\'day\')'
    );
    
    // 测试星期几获取
    // 输入: moment('2021-01-01T00:00:00Z') (星期五), day()
    const momentJsDayOfWeekResult = baseTime.clone().day();
    const moment4cjDayOfWeekResult = moment4cjResults.dayOfWeek;
    const dayOfWeekPassed = momentJsDayOfWeekResult === moment4cjDayOfWeekResult;
    
    addTestResult(
        '星期几获取测试',
        dayOfWeekPassed,
        momentJsDayOfWeekResult.toString(),
        moment4cjDayOfWeekResult !== undefined ? moment4cjDayOfWeekResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\') (星期五), day()'
    );
    
    // 测试一年中的第几天获取
    // 输入: moment('2021-01-01T00:00:00Z') (一年中的第一天), dayOfYear()
    const momentJsDayOfYearResult = baseTime.clone().dayOfYear();
    const moment4cjDayOfYearResult = moment4cjResults.dayOfYear;
    const dayOfYearPassed = momentJsDayOfYearResult === moment4cjDayOfYearResult;
    
    addTestResult(
        '一年中的第几天获取测试',
        dayOfYearPassed,
        momentJsDayOfYearResult.toString(),
        moment4cjDayOfYearResult !== undefined ? moment4cjDayOfYearResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\') (一年中的第一天), dayOfYear()'
    );
    
    // 测试一年中的第几周获取
    // 输入: moment('2021-01-01T00:00:00Z'), week()
    const momentJsWeekOfYearResult = baseTime.clone().week();
    const moment4cjWeekOfYearResult = moment4cjResults.weekOfYear;
    const weekOfYearPassed = momentJsWeekOfYearResult === moment4cjWeekOfYearResult;
    
    addTestResult(
        '一年中的第几周获取测试',
        weekOfYearPassed,
        momentJsWeekOfYearResult.toString(),
        moment4cjWeekOfYearResult !== undefined ? moment4cjWeekOfYearResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), week()'
    );
    
    // 测试week方法
    // 输入: moment('2021-01-01T00:00:00Z'), week()
    const momentJsWeekResult = baseTime.clone().week();
    const moment4cjWeekResult = moment4cjResults.week;
    const weekPassed = momentJsWeekResult === moment4cjWeekResult;
    
    addTestResult(
        'Week方法测试',
        weekPassed,
        momentJsWeekResult.toString(),
        moment4cjWeekResult !== undefined ? moment4cjWeekResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), week()'
    );
    
    // 测试年末week方法（边界情况）
    // 输入: moment('2021-12-27T00:00:00Z'), week()
    const endOfYearTime = moment('2021-12-27T00:00:00Z');
    const momentJsEndOfYearWeekResult = endOfYearTime.clone().week();
    const moment4cjEndOfYearWeekResult = moment4cjResults.endOfYearWeek;
    const endOfYearWeekPassed = momentJsEndOfYearWeekResult === moment4cjEndOfYearWeekResult;
    
    addTestResult(
        '年末Week方法测试（边界情况）',
        endOfYearWeekPassed,
        momentJsEndOfYearWeekResult.toString(),
        moment4cjEndOfYearWeekResult !== undefined ? moment4cjEndOfYearWeekResult.toString() : 'N/A',
        '输入: moment(\'2021-12-27T00:00:00Z\'), week()'
    );
    
    // 测试isoWeek方法
    // 输入: moment('2021-01-01T00:00:00Z'), isoWeek()
    const momentJsIsoWeekResult = baseTime.clone().isoWeek();
    const moment4cjIsoWeekResult = moment4cjResults.isoWeek;
    const isoWeekPassed = momentJsIsoWeekResult === moment4cjIsoWeekResult;
    
    addTestResult(
        'IsoWeek方法测试',
        isoWeekPassed,
        momentJsIsoWeekResult.toString(),
        moment4cjIsoWeekResult !== undefined ? moment4cjIsoWeekResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), isoWeek()'
    );
    
    // 测试weeks方法
    // 输入: moment('2021-01-01T00:00:00Z'), weeks()
    const momentJsWeeksResult = baseTime.clone().weeks();
    const moment4cjWeeksResult = moment4cjResults.weeks;
    const weeksPassed = momentJsWeeksResult === moment4cjWeeksResult;
    
    addTestResult(
        'Weeks方法测试',
        weeksPassed,
        momentJsWeeksResult.toString(),
        moment4cjWeeksResult !== undefined ? moment4cjWeeksResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), weeks()'
    );
    
    // 测试年末weeks方法（边界情况）
    // 输入: moment('2021-12-27T00:00:00Z'), weeks()
    const momentJsEndOfYearWeeksResult = endOfYearTime.clone().weeks();
    const moment4cjEndOfYearWeeksResult = moment4cjResults.endOfYearWeeks;
    const endOfYearWeeksPassed = momentJsEndOfYearWeeksResult === moment4cjEndOfYearWeeksResult;
    
    addTestResult(
        '年末Weeks方法测试（边界情况）',
        endOfYearWeeksPassed,
        momentJsEndOfYearWeeksResult.toString(),
        moment4cjEndOfYearWeeksResult !== undefined ? moment4cjEndOfYearWeeksResult.toString() : 'N/A',
        '输入: moment(\'2021-12-27T00:00:00Z\'), weeks()'
    );
    
    // 测试isoWeeks方法
    // 输入: moment('2021-01-01T00:00:00Z'), isoWeeks()
    const momentJsIsoWeeksResult = baseTime.clone().isoWeeks();
    const moment4cjIsoWeeksResult = moment4cjResults.isoWeeks;
    const isoWeeksPassed = momentJsIsoWeeksResult === moment4cjIsoWeeksResult;
    
    addTestResult(
        'IsoWeeks方法测试',
        isoWeeksPassed,
        momentJsIsoWeeksResult.toString(),
        moment4cjIsoWeeksResult !== undefined ? moment4cjIsoWeeksResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), isoWeeks()'
    );
    
    // 测试季度获取
    // 输入: moment('2021-01-01T00:00:00Z') (第一季度), quarter()
    const momentJsQuarterResult = baseTime.clone().quarter();
    const moment4cjQuarterResult = moment4cjResults.quarter;
    const quarterPassed = momentJsQuarterResult === moment4cjQuarterResult;
    
    addTestResult(
        '季度获取测试',
        quarterPassed,
        momentJsQuarterResult.toString(),
        moment4cjQuarterResult !== undefined ? moment4cjQuarterResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\') (第一季度), quarter()'
    );
    
    // 测试get方法
    // 输入: moment('2021-01-01T00:00:00Z'),
    //       get('year'), get('month'), get('date')
    const momentJsGetResult = {
        year: baseTime.clone().get('year'),
        month: baseTime.clone().get('month'),
        date: baseTime.clone().get('date')
    };
    const moment4cjGetResult = moment4cjResults.get;
    const getPassed = moment4cjGetResult && 
                     momentJsGetResult.year === moment4cjGetResult.year &&
                     momentJsGetResult.month === moment4cjGetResult.month && 
                     momentJsGetResult.date === moment4cjGetResult.date;
    
    addTestResult(
        'Get方法测试',
        getPassed,
        `${momentJsGetResult.year},${momentJsGetResult.month},${momentJsGetResult.date}`,
        moment4cjGetResult ? `${moment4cjGetResult.year},${moment4cjGetResult.month},${moment4cjGetResult.date}` : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), get(\'year\'), get(\'month\'), get(\'date\')'
    );
    
    // 测试set方法
    // 输入: moment('2021-01-01T00:00:00Z'),
    //       set('year', 2022).set('month', 5).set('date', 15)
    const momentJsSetResult = baseTime.clone().set('year', 2022).set('month', 5).set('date', 15).format('YYYY-MM-DD');
    const moment4cjSetResult = moment4cjResults.set;
    const setPassed = momentJsSetResult === moment4cjSetResult;
    
    addTestResult(
        'Set方法测试',
        setPassed,
        momentJsSetResult,
        moment4cjSetResult || 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), set(\'year\', 2022).set(\'month\', 5).set(\'date\', 15)'
    );
    
    // 测试Unix时间戳获取
    // 输入: moment('2021-01-01T00:00:00Z'), unix()
    const momentJsUnixTimestampResult = baseTime.clone().unix();
    const moment4cjUnixTimestampResult = moment4cjResults.unixTimestamp;
    const unixTimestampPassed = momentJsUnixTimestampResult === moment4cjUnixTimestampResult;
    
    addTestResult(
        'Unix时间戳获取测试',
        unixTimestampPassed,
        momentJsUnixTimestampResult.toString(),
        moment4cjUnixTimestampResult ? moment4cjUnixTimestampResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), unix()'
    );
    
    // 测试月份天数获取
    // 输入: moment('2021-01-01T00:00:00Z') (一月), daysInMonth()
    const momentJsDaysInMonthResult = baseTime.clone().daysInMonth();
    const moment4cjDaysInMonthResult = moment4cjResults.daysInMonth;
    const daysInMonthPassed = momentJsDaysInMonthResult === moment4cjDaysInMonthResult;
    
    addTestResult(
        '月份天数获取测试',
        daysInMonthPassed,
        momentJsDaysInMonthResult.toString(),
        moment4cjDaysInMonthResult ? moment4cjDaysInMonthResult.toString() : 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\') (一月), daysInMonth()'
    );
    
    // 测试calendar方法
    // 输入: moment = moment('2021-01-01T00:00:00Z'),
    //       now = moment('2021-01-02T00:00:00Z') (基准时间),
    //       calendar(now)
    const momentJsCalendarResult = baseTime.clone().calendar(moment('2021-01-02T00:00:00Z'));
    const moment4cjCalendarResult = moment4cjResults.calendar;
    const calendarPassed = momentJsCalendarResult === moment4cjCalendarResult;
    
    addTestResult(
        'Calendar方法测试',
        calendarPassed,
        momentJsCalendarResult,
        moment4cjCalendarResult || 'N/A',
        '输入: moment = moment(\'2021-01-01T00:00:00Z\'), now = moment(\'2021-01-02T00:00:00Z\') (基准时间), calendar(now)'
    );
    
    // 测试calendar方法（同一天）
    // 输入: moment('2021-01-01T00:00:00Z'), calendar(moment('2021-01-01T00:00:00Z'))
    const momentJsCalendarSameDayResult = moment('2021-01-01T00:00:00Z').calendar(moment('2021-01-01T00:00:00Z'));
    const moment4cjCalendarSameDayResult = moment4cjResults.calendarSameDay;
    const calendarSameDayPassed = momentJsCalendarSameDayResult === moment4cjCalendarSameDayResult;
    
    addTestResult(
        'Calendar方法测试（同一天）',
        calendarSameDayPassed,
        momentJsCalendarSameDayResult,
        moment4cjCalendarSameDayResult || 'N/A',
        '输入: moment(\'2021-01-01T00:00:00Z\'), calendar(moment(\'2021-01-01T00:00:00Z\'))'
    );
    
    // 测试calendar方法（下一天）
    // 输入: moment('2021-01-02T00:00:00Z'), calendar(moment('2021-01-01T00:00:00Z'))
    const momentJsCalendarNextDayResult = moment('2021-01-02T00:00:00Z').calendar(moment('2021-01-01T00:00:00Z'));
    const moment4cjCalendarNextDayResult = moment4cjResults.calendarNextDay;
    const calendarNextDayPassed = momentJsCalendarNextDayResult === moment4cjCalendarNextDayResult;
    
    addTestResult(
        'Calendar方法测试（下一天）',
        calendarNextDayPassed,
        momentJsCalendarNextDayResult,
        moment4cjCalendarNextDayResult || 'N/A',
        '输入: moment(\'2021-01-02T00:00:00Z\'), calendar(moment(\'2021-01-01T00:00:00Z\'))'
    );
    
    // 测试calendar方法（上周）
    // 输入: moment('2020-12-26T00:00:00Z') (Saturday),
    //       calendar(moment('2021-01-01T00:00:00Z') (Friday))
    const momentJsCalendarLastWeekResult = moment('2020-12-26T00:00:00Z').calendar(moment('2021-01-01T00:00:00Z'));
    const moment4cjCalendarLastWeekResult = moment4cjResults.calendarLastWeek;
    const calendarLastWeekPassed = momentJsCalendarLastWeekResult === moment4cjCalendarLastWeekResult;
    
    addTestResult(
        'Calendar方法测试（上周）',
        calendarLastWeekPassed,
        momentJsCalendarLastWeekResult,
        moment4cjCalendarLastWeekResult || 'N/A',
        '输入: moment(\'2020-12-26T00:00:00Z\') (Saturday), calendar(moment(\'2021-01-01T00:00:00Z\') (Friday))'
    );
    
    // 测试calendar方法（下周）
    // 输入: moment('2021-01-03T00:00:00Z') (Sunday),
    //       calendar(moment('2021-01-01T00:00:00Z') (Friday))
    const momentJsCalendarNextWeekResult = moment('2021-01-03T00:00:00Z').calendar(moment('2021-01-01T00:00:00Z'));
    const moment4cjCalendarNextWeekResult = moment4cjResults.calendarNextWeek;
    const calendarNextWeekPassed = momentJsCalendarNextWeekResult === moment4cjCalendarNextWeekResult;
    
    addTestResult(
        'Calendar方法测试（下周）',
        calendarNextWeekPassed,
        momentJsCalendarNextWeekResult,
        moment4cjCalendarNextWeekResult || 'N/A',
        '输入: moment(\'2021-01-03T00:00:00Z\') (Sunday), calendar(moment(\'2021-01-01T00:00:00Z\') (Friday))'
    );
    
    // 测试calendar方法（超过一周）
    // 输入: moment('2020-12-25T00:00:00Z'),
    //       calendar(moment('2021-01-01T00:00:00Z'))
    const momentJsCalendarSameElseResult = moment('2020-12-25T00:00:00Z').calendar(moment('2021-01-01T00:00:00Z'));
    const moment4cjCalendarSameElseResult = moment4cjResults.calendarSameElse;
    const calendarSameElsePassed = momentJsCalendarSameElseResult === moment4cjCalendarSameElseResult;
    
    addTestResult(
        'Calendar方法测试（超过一周）',
        calendarSameElsePassed,
        momentJsCalendarSameElseResult,
        moment4cjCalendarSameElseResult || 'N/A',
        '输入: moment(\'2020-12-25T00:00:00Z\'), calendar(moment(\'2021-01-01T00:00:00Z\'))'
    );
}

// 生成验证报告
function generateReport() {
    const passedTests = validationReport.summary.passedTests;
    const totalTests = validationReport.summary.totalTests;
    const failedTests = validationReport.summary.failedTests;
    
    const reportData = {
        summary: {
            totalTests,
            passedTests,
            failedTests
        },
        testCases: validationReport.testCases
    };
    
    // 生成Markdown格式报告
    let markdownReport = `# Moment.js 与 Moment4CJ 交叉验证测试报告\n\n`;
    markdownReport += `## 测试摘要\n\n`;
    markdownReport += `- **总测试数**: ${totalTests}\n`;
    markdownReport += `- **通过测试数**: ${passedTests}\n`;
    markdownReport += `- **失败测试数**: ${failedTests}\n`;
    markdownReport += `- **通过率**: ${totalTests > 0 ? ((passedTests / totalTests) * 100).toFixed(2) : 0}%\n\n`;
    
    markdownReport += `## 测试详情\n\n`;
    
    validationReport.testCases.forEach(result => {
        markdownReport += `### ${result.name}\n`;
        markdownReport += `- 结果: ${result.passed ? '✅ 通过' : '❌ 失败'}\n`;
        markdownReport += `- Moment.js 结果: ${result.momentResult}\n`;
        markdownReport += `- Moment4CJ 结果: ${result.moment4cjResult}\n`;
        if (result.details) {
            markdownReport += `- 输入: ${result.details}\n`;
        }
        markdownReport += '\n';
    });
    
    // 写入Markdown报告到CrossTest目录
    fs.writeFileSync(path.join(__dirname, 'validation_report.md'), markdownReport);
    console.log('验证报告已生成: CrossTest/validation_report.md');
    
    // 写入JSON格式报告到CrossTest目录
    fs.writeFileSync(path.join(__dirname, 'validation_report.json'), JSON.stringify(reportData, null, 2));
    console.log('JSON格式验证报告已生成: CrossTest/validation_report.json');
}

// 主函数
function main() {
    console.log('开始执行Moment.js与Moment4CJ交叉验证测试...');
    
    try {
        performCrossValidation();
        generateReport();
        
        console.log('交叉验证测试完成!');
        console.log(`总测试数: ${validationReport.summary.totalTests}`);
        console.log(`通过测试数: ${validationReport.summary.passedTests}`);
        console.log(`失败测试数: ${validationReport.summary.failedTests}`);
        console.log(`通过率: ${validationReport.summary.totalTests > 0 ? (validationReport.summary.passedTests / validationReport.summary.totalTests * 100).toFixed(2) : 0}%`);
    } catch (error) {
        console.error('执行测试时发生错误:', error);
    }
}

// 执行主函数
main();